<template>
  <div class="m-bottom">
    <el-checkbox-group v-model="checkedList" @change="handleCheckedChange">
      <el-checkbox v-for="item in dataList" :key="item.id" :label="item.fn_title" :value="item.id">
        <span v-html="item.fn_title"></span>
        <div class="b-checkbox-box">
          <div class="c-b-left">
            <el-image class="border-2px border-#e0e3e9 border-solid" style="height: 160px;" :src="JSON.parse(item.fn_cover)[0].url || '@/assets/images/error.png'"
                 alt="">
              <template #error>
                <el-image :src="bookLogo" style="height: 160px"></el-image>
              </template>
            </el-image>
          </div>
          <div class="c-b-right">
            <el-descriptions :column="1">
              <el-descriptions-item label="作者" v-if="item.fn_author"><span v-html="item.fn_author"></span>
              </el-descriptions-item>
              <el-descriptions-item label="出版年月">
                {{ item.fn_pubdate ? item.fn_pubdate.substring(0, 7) : '' }}
              </el-descriptions-item>
              <el-descriptions-item label="价格" v-if="item.fn_price"
              ><span class="b-checkbox-color-red">{{ item.fn_price }}</span></el-descriptions-item
              >
              <el-descriptions-item label="关键字">
                <el-tag effect="plain" size="small">战争</el-tag>
                <el-tag effect="plain" size="small">历史</el-tag>
              </el-descriptions-item>
              <el-descriptions-item>
                <el-button type="primary" size="small" @click="Detail">查看详情</el-button>
                <el-button type="success" size="small">下载申请</el-button>
              </el-descriptions-item>
            </el-descriptions>
          </div>
        </div>
      </el-checkbox>
    </el-checkbox-group>

  </div>
</template>
<script setup>
import {ref} from 'vue'
import {propTypes} from "../../../utils/propTypes";
import bookLogo from '@/assets/imgs/bookLogo.webp'

const props = defineProps({
  dataList: propTypes.array.def([]),
  keyword: propTypes.string.def(''),
  checkedList: propTypes.array.def([])
})
const checkedList = ref([])
const isIndeterminate = defineModel()
const handleCheckedChange = (value) => {
  const checkedCount = value.length
  isIndeterminate.value = checkedCount > 0 && checkedCount < dataList.length
}
// 查看详情
const Detail = () => {
  const url = `${window.location.origin}/search/book/detail?metaId=${42}&detailsId=${1}&buttonState=${false}`
  window.open(url, '_blank')
}
defineExpose({
  checkedList,
})
</script>
<style scoped lang="scss">
.m-bottom {
  .el-checkbox-group {
    display: flex;
    flex-wrap: wrap;

    .el-checkbox {
      width: 50%;
      height: 200px;
      margin: 0 0 30px 0;
    }

    ::v-deep(.el-checkbox__label) {
      margin-top: 30px;
      padding: 10px;
      box-sizing: border-box;
    }
  }

  .b-checkbox-box {
    margin-top: 10px;
    display: flex;
    justify-content: center;
    align-items: center;

    .c-b-left {
      margin-right: 10px;
      border: 1px solid #e2e8f0;
    }

    .c-b-right {
      .el-tag {
        margin-right: 10px;
      }
    }
  }
}
</style>
